﻿/// ---------------------------------------------
/// 2012.5.21
/// 汪定新
///
/// ---------------------------------------------
//双击事件
function CustomDbClick() {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    var id = record.getData(const_entityID);
    var applyMan = record.getData("CName"); //申请人
    var applyDate = record.getData("ReportDate"); //申请日期
    var postName = record.getData("PostName"); //需求岗位
    document.getElementById("dialog1_h").innerHTML = "查看招聘需求";
    document.getElementById("EditUIWindow").src = encodeURI("../Extend/AutoLoadForm.aspx?id=" + id + "&entity=" + const_EditEntity + "&fun=view&applyMan=" + applyMan + "&applyDate=" + applyDate + "&postName=" + postName);
    SetDWH(500, 420, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}
//获取url里的参数值 name:参数名称
function getPar(source, name) {
    var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
    if (reg.test(source))
        return RegExp.$2;
    return "";
};
//----------------------------------------------
//添加
var fnCustomAdd = function () {
    document.getElementById("dialog1_h").innerHTML = "新增招聘需求";
    document.getElementById("EditUIWindow").src = "../Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=" + const_EditEntity+"&fun=add";
    SetDWH(500, 420, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}
//编辑
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    if (record.getData("status") != "待审核")//已审核过的不能再编辑
    {
        alert("已经审核过了,不允许编辑!");
        return;
    }
    var applyMan = record.getData("CName"); //申请人
    var applyDate = record.getData("ReportDate"); //申请日期
    document.getElementById("dialog1_h").innerHTML = "修改招聘需求";
    document.getElementById("EditUIWindow").src = encodeURI("../Extend/AutoLoadForm.aspx?id=" + record.getData(const_entityID) + "&entity=" + const_EditEntity + "&fun=edit&applyMan=" + applyMan + "&applyDate=" + applyDate);
    SetDWH(500, 420, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}
//招聘需求审核
var fnRecruitmentDemandAudit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    if (record.getData("status") != "待审核")//已审核过的不能再审核
    {
        alert("已经审核过了,不能重复审核!");
        return;
    }
    var id = record.getData(const_entityID);
    var applyMan = record.getData("CName"); //申请人
    var applyDate = record.getData("ReportDate"); //申请日期
    var postName = record.getData("PostName"); //需求岗位
    document.getElementById("dialog1_h").innerHTML = "招聘需求审核";
    document.getElementById("EditUIWindow").src = encodeURI("../Extend/AutoLoadForm.aspx?id=" + id + "&entity=" + const_EditEntity + "&fun=audit&applyMan=" + applyMan + "&applyDate=" + applyDate+"&postName="+postName);
    SetDWH(520, 500, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

//页面加载时
if (typeof ($) != "undefined") {
    $(document).ready(function () {
//        var obj = document.getElementById("yui-gen7-button");
//        obj.setAttribute("onclick", "Save();");
    });
}

//保存招聘计划明细
function Save() {
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData[const_entityID]);
        }
    }
    var url = "";
    var RecruitmentPlanID = getPar(location.href, "id");
    if (elist.length == 0) {
        var recordID = myDataTable.getSelectedRows()[0];
        record = myDataTable.getRecord(recordID);
        if (record == null) {
            alert("请至少选择一条记录!");
            return;
        }
        var id = record.getData(const_entityID);
        url = "../EHR/hrRecruitmentAjax.aspx?flag=RecruitmentDetailSave&fun=add&id=" + id + "&RecruitmentPlanID=" + RecruitmentPlanID; //单条记录
    }
    else {
        var json = elist.join(",");
        url = "../EHR/hrRecruitmentAjax.aspx?flag=RecruitmentDetailSave&fun=add&json=" + json + "&RecruitmentPlanID=" + RecruitmentPlanID; //多条记录
    }
    YAHOO.util.Connect.asyncRequest('POST', url, {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "0") {
                        alert("恭喜，保存成功!");
                        parent.dialog.hide();
                        parent.LoadData();
                    }
                    else {
                        alert("很遗憾，保存失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
}


//查看候选人
var fnResumeList = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    if (record.getData("Status") == "审核不通过" || record.getData("Status") == "待审核")//已审核过才能查看候选人列表
    {
        alert("岗位需求提报未通过审核或未审核，不能查看投递该岗位简历的人才信息!");
        return;
    }
    var id = record.getData(const_entityID);
    document.getElementById("yui-gen7-button").style.display = "none";
    document.getElementById("dialog1_h").innerHTML = record.getData("PositionName") + "-----岗位人才信息";
    document.getElementById("EditUIWindow").src = "../Extend/YUIDataTableList.aspx?&isShonwBtn=N&r=" + Math.random() + "&entity=V_hrCandidate&functionid=ED5F4CB8-3E1A-4764-A618-1488716CC0BA&condition=RequirementID='" + id + "'&order=InterviewStatus"; //functionid=ED5F4CB8-3E1A-4764-A618-1488716CC0BA
    SetDWH(900, 500, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}